package Java.BlackHorse.IO.zipStream;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class IODemo1 {
    public static void main(String[] args) throws IOException {
        File src = new File("IO\\zipStream\\aaa.zip");
        File dest = new File("IO\\zipStream");
        unzip(src,dest);
    }

    public static void unzip(File src, File dest) throws IOException{
//        压缩包的每一个 文件\文件夹 都是entry对象
        ZipInputStream zip = new ZipInputStream(new FileInputStream(src));
//        先从压缩包中读取每个 entry 对象
        ZipEntry entry ;
        while((entry = zip.getNextEntry()) != null){
            System.out.println(entry);
            if(entry.isDirectory()){
                File f = new File(dest,entry.toString());
                f.mkdirs();
            }else{
                FileOutputStream fos = new FileOutputStream(new File(dest,entry.toString()));
                int b;
                while((b = zip.read()) != -1){
                    fos.write(b);
                }
                fos.close();
            }
        }
        zip.close();
    }
}
